// JavaScript Document

// bannerSlide /////////////////////////////////////////////////////////////////
(function ($) {
    $.fn.bannerSlide = function (options) {
        var defaults = {
            showTitle: false,  // 是否显示标题
            showButtonList: true, // 是否显示动画按钮列表 true/false;
            showArrowList: false, // 是否显示前进后退控制箭头按钮 true/false;
            switchDistanceRatio: 0.2, // 触发滑动切换的距离, 比率模式0-1之间，默认0.2，建议0.3以下
            touchDistanceRatio: 1, // 触摸下可滑动的最大距离 比率模式 0-1之间 默认1
            bannerLoop: false, // banner 是否循环模式			  			
            easing: "linear", // 动画曲线 css3 ease
            interval: true, // true/false 是否自动执行循环播放
            loadCallback: null  // 幻灯片加载完成执行函数
        };

        var newOptions = $.extend(true, {}, defaults, options);
        return this.each(function () {

            // 取得控件
            var obj = $(this),
			    objList = obj.children("ul"),
				// 按钮列表控制控件id,箭头控制id 
				buttonListClientId = "btn" + obj.attr("id") + "List",
				arrowListPrevClientId = "arrow" + obj.attr("id") + "Prev",
				arrowListNextClientId = "arrow" + obj.attr("id") + "Next",

				objButtonList = $("#" + buttonListClientId),
				objArrowListPrev = $("#" + arrowListPrevClientId),
				objArrowListNext = $("#" + arrowListNextClientId),

				// 取得幻灯片列表的数量 
				size = objList.children().size(),

				// 取得幻灯片显示长度
				width = obj.width(),
				// 当前索引项
				crtIndex = 0,
				// 变换规则
				slideRule = "right",
				// 循环播放Id
				intervalId = null,
				// 当前滑动水平距离
				crtDistHV = [0, 0],
				// 触发滑动切换的距离 / 触发滑动的最大距离 / 触摸边界最大滑动距离
				touchDistSTB = [width * newOptions.switchDistanceRatio, width * newOptions.touchDistanceRatio, width * 0.1],
				// 触摸坐标
				startPoint = [0, 0],
				endPoint = [0, 0],
				// 触摸支持
				touchSupport = document.hasOwnProperty("ontouchstart"),  // true/false
				// 幻灯片状态
				status = 0; // 非滑动状态-0, 滑动状态-1

            // css修饰控件 
            objList.css({ "width": ((size > 0) ? width * size : width) + "px", "position": "relative", "left": "0", "top": "0" });
            objList.children().css({ "width": width + "px", "float": "left","position":"static"});
            // css 循环修饰 data
            objList.children().each(function (index, element) {
                $(element).attr("rel", index);
            });

            //////////////////////////////////////////

            // 控制按钮对应特效函数
            function effectButtonList() {
                // btnList对应
                if (objButtonList && objButtonList.length > 0) {
                    objButtonList.find("a").removeClass("checked").eq(parseInt(objList.children(":eq(" + crtIndex + ")").attr("rel"))).addClass("checked");
                };
            };

            // 加载控制按钮列表
            function loadButtonList() {

                // 判断是否需要加载
                if (newOptions.showButtonList) {

                    // 已存在删除
                    if (objButtonList && objButtonList.length > 0) {
                        objButtonList.remove();
                    };

                    // 重新组合DOM
                    var btnListHtml = "<div id='" + buttonListClientId + "' class='listbtn'><div class='listbtn-inner'>";

                    for (var i = 1; i <= size; i++) {

                        if (i == 1) {
                            btnListHtml += "<a class='checked' href='javascript:void(0);'><span>" + i + "</span></a>\n";
                        } else {
                            btnListHtml += "<a href='javascript:void(0);'><span>" + i + "</span></a>\n";
                        };

                    };

                    btnListHtml += "</div></div>";

                    // 添加控制按钮列表html
                    obj.append(btnListHtml);

                    // 重新取得控件
                    objButtonList = $("#" + buttonListClientId);
                };

            };

            // 控制箭头点击特效
            function effectArrowList() {

                var left = null;
                var transition = null;

                if (crtIndex == 0 && newOptions.bannerLoop && slideRule == "left") { // 第一张

                    objList.prepend(objList.children(":eq(" + (size - 1) + ")").detach());

                    transition = "left 0s " + newOptions.easing + " 0";
                    left = (-(width)) + "px";
                    objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                    crtIndex = 0;

                    setTimeout(function () {
                        transition = "left 0.3s " + newOptions.easing + " 0";
                        left = (-(crtIndex * width)) + "px";
                        objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        window.setTimeout(function () { effectButtonList(); status = 0; }, 300);
                    }, 100);

                } else if (crtIndex == 0 && slideRule == "left") { // 第一张

                    left = touchDistSTB[2] + "px";
                    transition = "left 0.2s " + newOptions.easing + " 0";
                    status = 1;

                    objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });

                    window.setTimeout(function () {
                        transition = "left 0.2s " + newOptions.easing + " 0";
                        objList.css({ "left": "0px", "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        window.setTimeout(function () { status = 0; }, 200);
                    }, 300);

                } else if (crtIndex == (size - 1) && newOptions.bannerLoop && slideRule == "right") {

                    objList.append(objList.children(":eq(0)").detach());

                    transition = "left 0s " + newOptions.easing + " 0";
                    left = (-((size - 2) * width)) + "px";
                    objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                    crtIndex = size - 1;

                    setTimeout(function () {
                        transition = "left 0.3s " + newOptions.easing + " 0";
                        left = (-(crtIndex * width)) + "px";
                        objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        window.setTimeout(function () { effectButtonList(); status = 0; }, 300);
                    }, 100);

                } else if (crtIndex == (size - 1) && slideRule == "right") { // 最后一张

                    left = ((-(crtIndex * width)) + (-touchDistSTB[2])) + "px";
                    transition = "left 0.2s " + newOptions.easing + " 0";
                    status = 1;

                    objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });

                    window.setTimeout(function () {
                        left = (-(crtIndex * width)) + "px";
                        transition = "left 0.2s " + newOptions.easing + " 0";
                        objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        window.setTimeout(function () { status = 0; }, 200);
                    }, 300);

                } else {

                    transition = "left 0.3s " + newOptions.easing + " 0";

                    if (slideRule == "left") {
                        crtIndex--;
                    } else if (slideRule == "right") {
                        crtIndex++;
                    };

                    left = (-(crtIndex * width)) + "px";
                    status = 1;

                    objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                    window.setTimeout(function () { effectButtonList(); status = 0; }, 300);

                };

            };

            // 加载控制箭头列表
            function loadArrowList() {

                // 判断是否需要加载
                if (newOptions.showArrowList) {

                    // 已存在删除
                    if (objArrowListPrev && objArrowListPrev.length > 0) {
                        objArrowListPrev.remove();
                    };

                    if (objArrowListNext && objArrowListNext.length > 0) {
                        objArrowListNext.remove();
                    };

                    // 重新组合DOM 
                    var arrowListHtml = "<div id='arrow" + obj.attr("id") + "Prev' class='arrowlft'><a href='#'></a></div>";

                    arrowListHtml += "<div id='arrow" + obj.attr("id") + "Next' class='arrowrht'><a href='#'></a></div>";

                    // 添加控制箭头DOM
                    obj.append(arrowListHtml);

                    // 再次取得控件
                    objArrowListPrev = $("#" + arrowListPrevClientId);
                    objArrowListNext = $("#" + arrowListNextClientId);

                    // 绑定事件
                    $("> a", objArrowListPrev).click(function (e) {

                        e.preventDefault();

                        // 清理自动播放
                        if (newOptions.interval && intervalId) {
                            window.clearInterval(intervalId);
                            intervalId = null;
                        };

                        slideRule = "left";
                        effectArrowList();
                    });

                    $("> a", objArrowListNext).click(function (e) {

                        e.preventDefault();

                        // 清理自动播放
                        if (newOptions.interval && intervalId) {
                            window.clearInterval(intervalId);
                            intervalId = null;
                        };

                        slideRule = "right";
                        effectArrowList();
                    });

                };

            };

            // 触摸下的滑动函数
            function touchMoving() {

                var left = null;
                var transition = "left 0 " + newOptions.easing + " 0";

                if ((crtDistHV[0] > 0) && (crtIndex == 0)) { // 第一张

                    if (newOptions.bannerLoop) {

                        objList.prepend(objList.children(":eq(" + (size - 1) + ")").detach());
                        left = (-(width)) + "px";
                        crtIndex = 1;

                        if ((Math.abs(crtDistHV[0]) <= touchDistSTB[1])) {
                            left = ((-(width)) + crtDistHV[0]) + "px";
                        };

                    } else {
                        left = ((crtDistHV[0] > touchDistSTB[2]) ? touchDistSTB[2] : crtDistHV[0]) + "px";
                    };

                } else if ((crtDistHV[0] < 0) && (crtIndex == (size - 1))) { // 最后一张

                    if (newOptions.bannerLoop) {

                        objList.append(objList.children(":eq(0)").detach());
                        left = (-((size - 2) * width)) + "px";
                        crtIndex = size - 2;

                        if ((Math.abs(crtDistHV[0]) <= touchDistSTB[1])) {
                            left = (-((size - 2) * width)) + crtDistHV[0] + "px";
                        };

                    } else {
                        left = ((-(crtIndex * width)) + ((Math.abs(crtDistHV[0]) > touchDistSTB[2]) ? (-touchDistSTB[2]) : crtDistHV[0])) + "px";
                    };

                } else {

                    if ((crtDistHV[0] != 0) && (Math.abs(crtDistHV[0]) <= touchDistSTB[1])) {

                        left = ((-(crtIndex * width)) + crtDistHV[0]) + "px";

                    };

                };

                if (left) {
                    objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                };
            };

            // 触摸结束的幻灯效果
            function touchEndMoving(callback) {

                var left = null;
                var transition = "left 0.2s " + newOptions.easing + " 0";

                if ((crtDistHV[0] > 0) && (crtIndex == 0)) { // 第一张

                    left = "0px";

                } else if ((crtDistHV[0] < 0) && (crtIndex == (size - 1))) { // 最后一张

                    left = (-(crtIndex * width)) + "px";

                } else {

                    if (Math.abs(crtDistHV[0]) > touchDistSTB[0]) {
                        crtIndex = (crtDistHV[0] > 0) ? (crtIndex - 1) : (crtIndex + 1);
                    };

                    left = (-(crtIndex * width)) + "px"
                };

                if (left) {
                    status = 1;
                    objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                    window.setTimeout(function () { callback(); status = 0; }, 200);
                };
            };

            // 自动循环播放
            function autoMoving() {

                var left = null;
                var transition = null;
                status = 1;

                // 按条件判断
                if (crtIndex == 0) {

                    // 第一张
                    if (newOptions.bannerLoop && slideRule == "left") {

                        objList.prepend(objList.children(":eq(" + (size - 1) + ")").detach());

                        transition = "left 0s " + newOptions.easing + " 0";
                        left = (-(width)) + "px";
                        objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        crtIndex = 0;

                    } else {

                        slideRule = "right";
                        crtIndex++;

                    };

                } else if (crtIndex == (size - 1)) {

                    // 最后一张
                    if (newOptions.bannerLoop && slideRule == "right") {

                        objList.append(objList.children(":eq(0)").detach());

                        transition = "left 0s " + newOptions.easing + " 0";
                        left = (-((size - 2) * width)) + "px";
                        objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        crtIndex = size - 1;

                    } else {

                        slideRule = "left";
                        crtIndex--;

                    };

                } else {

                    if (slideRule == "left") {
                        crtIndex--;
                    } else if (slideRule == "right") {
                        crtIndex++;
                    };

                };

                setTimeout(function () {
                    transition = "left 0.3s " + newOptions.easing + " 0";
                    left = (-(crtIndex * width)) + "px";
                    objList.css({ "left": left, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                    window.setTimeout(function () { effectButtonList(); status = 0; }, 300);
                }, 100);

            };

            // 滑动事件touchStart
            function touchStart(e) {

                // 清理自动播放
                if (newOptions.interval && intervalId) {
                    window.clearInterval(intervalId);
                    intervalId = null;
                };

                // 判断是否支持触摸事件
                if (touchSupport) {

                    // 取得坐标
                    startPoint = endPoint = [e.touches[0].pageX, e.touches[0].pageY];

                } else {

                    // 取得坐标
                    startPoint = endPoint = [e.pageX, e.pageY];

                };

                // 触摸距离
                crtDistHV = [0, 0];

            };

            // 滑动事件touchMove
            function touchMove(e) {

                // 判断是否支持触摸事件
                if (touchSupport) {

                    // 取得坐标
                    endPoint = [e.touches[0].pageX, e.touches[0].pageY];

                } else {

                    // 取得坐标
                    endPoint = [e.pageX, e.pageY];

                };

                // 触摸距离
                crtDistHV = [endPoint[0] - startPoint[0], endPoint[1] - startPoint[1]];

                // 判断主方向是水平还是垂直
                if (Math.abs(crtDistHV[0]) > Math.abs(crtDistHV[1]) && status == 0) {

                    e.preventDefault();

                    // 触摸下的滑动
                    touchMoving();

                };

            };

            // 滑动事件 touchend
            function touchEnd(e) {

                // 判断滑动方向
                if (Math.abs(crtDistHV[0]) > Math.abs(crtDistHV[1]) && Math.abs(crtDistHV[0]) > 10 && status == 0) {

                    // 水平变换规则
                    if (crtDistHV[0] > 0) {

                        slideRule = "left";

                    } else if (crtDistHV[0] < 0) {

                        slideRule = "right";

                    };

                    // 触摸结束的滑动
                    touchEndMoving(function () {

                        // btnList对应变换特效
                        effectButtonList();

                        // 启用自动播放
                        if (newOptions.interval && !intervalId) {
                            intervalId = window.setInterval(autoMoving, 4000);
                        };

                    });

                };

            };

            // 幻灯片加载函数
            function loadSlideImage() {

                // 取得第一张图片
                var imgFirst = objList.children(":first").find("img");

                // 创建image对象
                var image = new Image();

                image.onload = function () {

                    // 取得图片原尺寸
                    var imgWidth = image.width, imgHeight = image.height;

                    // 新算法 开始////////////////////////////////////////////////////////////////

                    var scale = 1;

                    if (imgWidth > 960) {

                        scale = (width < 960) ? (width / 960) : 1;

                    } else {

                        scale = (width < imgWidth) ? (width / imgWidth) : 1;
                    };

                    imgWidth *= scale;
                    imgHeight *= scale;

                    // 配置图片居中显示
                    var imgMargin = "0 auto";

                    // 对比图片尺码
                    if (imgWidth > width) {

                        imgMargin = "0 -" + (imgWidth - width) / 2 + "px";
                    };

                    imgHeight += "px";

                    // 遍历配置所有图片重新设置高度
                    $("img", objList.children()).css({ "height": imgHeight, "margin": imgMargin });

                    // css再次修饰
                    obj.css("height", imgHeight);
                    objList.css("height", imgHeight);


                    //新算法 结束/////////////////////////////////////////////////////////////////

                    // 判断是否显示图片标题
                    if (!newOptions.showTitle) {

                        // 隐藏蒙板和标题
                        objList.children().each(function () {
                            $(this).children().children(":eq(1)").hide();
                        });

                        // 判断控制按钮
                        if (objButtonList) {
                            objButtonList.children().css("text-align", "center"); // 居中显示
                        };

                    };

                    // 判断是否为一张图片，隐藏蒙板和标题
                    if (size == 1) {
                        objList.children().children().children(":eq(1)").hide();
                    };

                    //////////////////////////////////////////////////////////////////////

                    if (size > 1) {

                        // 判断是否支持滑动事件
                        if (touchSupport) {

                            objList[0].addEventListener("touchstart", touchStart, false);
                            objList[0].addEventListener("touchmove", touchMove, false);
                            objList[0].addEventListener("touchend", touchEnd, false);
                            objList[0].addEventListener("touchcancel", touchEnd, false);

                        } else {

                            objList[0].addEventListener("mousedown", touchStart, false);
                            objList[0].addEventListener("mousemove", touchMove, false);
                            objList[0].addEventListener("mouseup", touchEnd, false);

                        };

                        // 是否执行自动播放
                        if (newOptions.interval) {
                            intervalId = setInterval(autoMoving, 4000);
                        };

                    };

                    // 执行回调loadCallback
                    if (newOptions.loadCallback) { newOptions.loadCallback(); };

                };

                image.src = imgFirst.attr("src");

                //////////////////////////////////////////////////////////////////////////////

            };

            /////////////////////////////////////////////////////////////////////////////////

            // 判断是否需要加载控制按钮列表及箭头列表
            if (size > 1) {

                // 判断是否加载ButtonList
                if (newOptions.showButtonList) { loadButtonList(); };

                // 判断是否加载ArrowList
                if (newOptions.showArrowList) { loadArrowList(); };

            };

            // 判断是否加载图片
            if (size > 0) { loadSlideImage(); };

            ////////////////////////////////////////////////////////////////

        });
    };
})(jQuery);

// screenSlide /////////////////////////////////////////////////////////////////
(function ($) {
    $.fn.screenSlide = function (options) {
        var defaults = {
            switchDistanceRatio: 0.1, // 触发滑动切换的距离, 比率模式0-1之间，默认0.2，建议0.3以下
            touchDistanceRatio: 1, // 触摸下可滑动的最大距离 比率模式 0-1之间 默认1
            slideLoop: false, // slide 是否循环模式			  			
            easing: "linear", // 动画曲线 css3 ease
            loadCallback: null  // 幻灯片加载完成执行函数
        };

        var newOptions = $.extend(true, {}, defaults, options);
        return this.each(function () {

            // 取得控件
            var obj = $(this),
			    objList = obj.children("ul"),
            // 取得幻灯片列表的数量 
				size = objList.children().size(),
            // 取得幻灯片显示尺寸
                width = obj.width(),
				height = obj.height(),
            // 当前索引
                crtIndex = 0, // 当前索引
            // 当前滑动距离
				crtDistHV = [0, 0],
            // 触发滑动切换的距离 / 触发滑动的最大距离 
				touchDistSTB = [height * newOptions.switchDistanceRatio, height * newOptions.touchDistanceRatio],
            // 触摸坐标
				startPoint = [0, 0],
				endPoint = [0, 0],
            // 触摸支持
				touchSupport = document.hasOwnProperty("ontouchstart"),  // true/false
            // 幻灯片状态
				status = 1, // 非滑动状态-0, 滑动状态-1
            // 当前对象和下一个对象
               objCrtChild = null,
               objNxtChild = null;

            // css 循环修饰
            objList.children().each(function (index, element) {
                if (index == 0) { $(element).css("z-index", size * 100); };
                $(element).attr("rel", index);
                var objContent = $("p", element);
                objContent.css({ "width": objContent.width() + "px", "height": objContent.height() + "px", "left": "-100%", "top": "10%", "right": "auto", "bottom": "auto", "border-radius": "0px 10px 10px 0px" });
            });

            //////////////////////////////////////////

            // 内容区动画
            function contentAnimation() {

                var objContent = objNxtChild.find("p");
                var transition;

                switch (parseInt(objNxtChild.attr("rel")) % 4) {
                    case 0:
                        transition = "left 1s linear 0s";
                        objContent.css({ "left": "0%", "top": "10%", "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        break;
                    case 1:
                        transition = "right 1s linear 0s";
                        objContent.css({ "right": "0%", "top": "10%", "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        break;
                    case 2:
                        transition = "left 1s linear 0s";
                        objContent.css({ "left": "0%", "bottom": "10%", "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        break;
                    case 3:
                        transition = "right 1s linear 0s";
                        objContent.css({ "right": "0%", "bottom": "10%", "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                        break;
                };

                window.setTimeout(function () {
                    transition = "all 0s linear 0s";
                    objContent.css({ "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                    objNxtChild = null;
                    status = 0;
                }, 1000);

            };

            // 触摸下的滑动函数
            function touchMoving() {

                var top = ((Math.abs(crtDistHV[1]) > touchDistSTB[1]) ? touchDistSTB[1] : crtDistHV[1]) + "px";
                var transition = "top 0 " + newOptions.easing + " 0";

                objCrtChild = objList.children(":eq(" + crtIndex + ")");

                objList.children().each(function (index, element) {
                    $(element).css("z-index", 0);
                });

                objCrtChild.css("z-index", size * 100);

                if (crtDistHV[1] > 0) {
                    if (crtIndex == 0 && newOptions.slideLoop) {
                        objNxtChild = objList.children(":eq(" + (size - 1) + ")");
                        objNxtChild.css("z-index", (size - 1) * 100);
                    } else if (crtIndex > 0) {
                        objNxtChild = objList.children(":eq(" + (crtIndex - 1) + ")");
                        objNxtChild.css("z-index", (size - 1) * 100);
                    } else {
                        top = null;
                    };
                } else if (crtDistHV[1] < 0) {
                    if (crtIndex == (size - 1) && newOptions.slideLoop) {
                        objNxtChild = objList.children(":eq(0)");
                        objNxtChild.css("z-index", (size - 1) * 100);
                    } else if (crtIndex < (size - 1)) {
                        objNxtChild = objList.children(":eq(" + (crtIndex + 1) + ")");
                        objNxtChild.css("z-index", (size - 1) * 100);
                    } else {
                        top = null;
                    };
                };

                if (objNxtChild) {

                    var objContent = objNxtChild.find("p");

                    switch (parseInt(objNxtChild.attr("rel")) % 4) {
                        case 0:
                            objContent.css({ "left": "-100%", "top": "10%", "right": "auto", "bottom": "auto", "border-radius": "0px 10px 10px 0px" });
                            break;
                        case 1:
                            objContent.css({ "left": "auto", "top": "10%", "right": "-100%", "bottom": "auto", "border-radius": "10px 0px 0px 10px" });
                            break;
                        case 2:
                            objContent.css({ "left": "-100%", "top": "auto", "right": "auto", "bottom": "10%", "border-radius": "0px 10px 10px 0px" });
                            break;
                        case 3:
                            objContent.css({ "left": "auto", "top": "auto", "right": "-100%", "bottom": "10%", "border-radius": "10px 0px 0px 10px" });
                            break;
                    };

                };

                if (top && objCrtChild) {
                    objCrtChild.css({ "top": top, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });
                };
            };

            // 触摸结束的幻灯效果
            function touchEndMoving() {

                var top = null;
                var transition = "top 0.5s " + newOptions.easing + " 0";

                if (crtDistHV[1] > 0) {
                    top = height + "px";
                    if (crtIndex == 0 && newOptions.slideLoop) {
                        crtIndex = size - 1;
                    } else if (crtIndex > 0) {
                        crtIndex -= 1;
                    } else {
                        top = null;
                    };
                } else {
                    top = (-height) + "px";
                    if (crtIndex == (size - 1) && newOptions.slideLoop) {
                        crtIndex = 0;
                    } else if (crtIndex < size - 1) {
                        crtIndex += 1;
                    } else {
                        top = null;
                    };
                };

                if (crtIndex < 0) { crtIndex = 0; }
                if (crtIndex > size - 1) { crtIndex = size - 1; }

                if (top && objCrtChild) {

                    status = 1;
                    objCrtChild.css({ "top": top, "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });

                    window.setTimeout(function () {
                        objCrtChild.css({ "top": "0", "z-index": "0" });

                        // 内容区动画
                        contentAnimation();

                    }, 1000);
                };
            };

            // 滑动事件touchStart
            function touchStart(e) {

                if (status == 0) {

                    $("> a.arrow", obj).hide();

                    // 判断是否支持触摸事件
                    if (touchSupport) {

                        // 取得坐标
                        startPoint = endPoint = [e.touches[0].pageX, e.touches[0].pageY];

                    } else {

                        // 取得坐标
                        startPoint = endPoint = [e.pageX, e.pageY];

                    };

                    // 触摸距离
                    crtDistHV = [0, 0];

                };

            };

            // 滑动事件touchMove
            function touchMove(e) {

                if (status == 0) {

                    // 判断是否支持触摸事件
                    if (touchSupport) {

                        // 取得坐标
                        endPoint = [e.touches[0].pageX, e.touches[0].pageY];

                    } else {

                        // 取得坐标
                        endPoint = [e.pageX, e.pageY];

                    };

                    // 触摸距离
                    crtDistHV = [endPoint[0] - startPoint[0], endPoint[1] - startPoint[1]];

                    // 判断主方向是水平还是垂直
                    if (Math.abs(crtDistHV[1]) > Math.abs(crtDistHV[0]) ) {

                        e.preventDefault();

                        // 触摸下的滑动
                        touchMoving();

                    };

                };

            };

            // 滑动事件 touchend
            function touchEnd(e) {

                if (status == 0) {

                    // 判断滑动方向
                    if (Math.abs(crtDistHV[1]) > Math.abs(crtDistHV[0]) && Math.abs(crtDistHV[1]) > 10) {

                        // 触摸结束的滑动
                        touchEndMoving();

                    };

                    $("> a.arrow", obj).show();

                };

            };

            /////////////////////////////////////////////////////////////////////////////////

            // 判断是否加载图片
            if (size > 0) {

                // 取得图片列表
                var objImgList = objList.children().find("img");

                // 加载事件
                objImgList.each(function (index, element) {

                    var objImg = $(element);

                    objImg.data("loaded", "false");

                    // 创建image对象
                    var image = new Image();

                    image.onload = function () {
                        objImg.data("loaded", "true");
                    };

                    image.src = objImg.attr("src");

                });

                // 循环判断图片是否全部加载完成
                var img_loaded = false;

                var id = window.setInterval(function () {

                    objImgList.each(function (index, element) {
                        if (Boolean($(element).data("loaded"))) {
                            img_loaded = true;
                        } else {
                            img_loaded = false;
                            return false;
                        };
                    });

                    if (img_loaded) {

                        // 清理
                        window.clearInterval(id);

                        // 加载滑动事件
                        if (size > 1) {

                            // 判断是否支持滑动事件
                            if (touchSupport) {

                                objList[0].addEventListener("touchstart", touchStart, false);
                                objList[0].addEventListener("touchmove", touchMove, false);
                                objList[0].addEventListener("touchend", touchEnd, false);
                                objList[0].addEventListener("touchcancel", touchEnd, false);

                            } else {

                                objList[0].addEventListener("mousedown", touchStart, false);
                                objList[0].addEventListener("mousemove", touchMove, false);
                                objList[0].addEventListener("mouseup", touchEnd, false);

                            };

                        };

                        // 执行回调loadCallback
                        if (newOptions.loadCallback) { newOptions.loadCallback(); };

                        // 音频控制
                        var objAudioControl = $("> a.audio", obj);
                        var objAudio = objAudioControl.find("audio");

                        objAudioControl.click(function (e) {
                            e.preventDefault();
                            if ($(this).hasClass("anim")) {
                                $(this).removeClass("anim");
                                objAudio[0].pause();
                            } else {
                                $(this).addClass("anim");
                                objAudio[0].play();
                            };
                        });

                        // 首次内容动画
                        var transition = "left 1s linear 0s";
                        var objContent = objList.children(":eq(0)").find("p");
                        objContent.css({ "left": "0%", "top": "10%", "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });

                        window.setTimeout(function () {
                            transition = "all 0s linear 0s";
                            objContent.css({ "transition": transition, "-webkit-transition": transition, "-ms-transition": transition, "-moz-transition": transition, "-o-transition": transition });

                            status = 0;
                        }, 1000);

                        ////////////////////////////////////////////////////

                    };

                }, 1000);

            };

            ///////////////////////////////////////////////////////////////////////////////////

        });
    };
})(jQuery);